//
//  PPAlbumImageModel.m
//  
//
//  Created by Jinxiao on 9/5/16.
//
//

#import "PPAlbumImageModel.h"

@implementation PPAlbumImageModel

// Insert code here to add functionality to your managed object subclass
+ (instancetype)existingAlbumImageForUUID:(NSString *)uuid {
    if(uuid.length == 0) {
        return nil;
    }
    
    PPAlbumImageModel *image = [self find:@{@"uuid": uuid}];
    if(image == nil) {
        image = [PPAlbumImageModel create];
        image.created = @(NO);
        image.deleted = @(NO);
        image.modified = @(NO);
        image.uuid = uuid;
        [image.managedObjectContext saveContext];
    }
    return image;
}

- (NSString *)URLString {
    if(self.key == nil || self.host == nil) {
        return nil;
    }

    return [NSString stringWithFormat:@"%@%@", self.host, self.key];
}

@end
